<?php

namespace App\Http\Controllers\Api\V1\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Carbon\Carbon;

class CouponResource extends JsonResource
{
    public function toArray($request)
    {
    	$resource = $this->resource;

        //dd($resource->destory_at);
        
        $data = [
        	
        	'id' => $resource->id,
        	'name' => $resource->coupon->name ?? '',
        	'full_price' => $resource->coupon->full_price ?? '',
        	'decrement_price' => (int)$resource->coupon->decrement_price ?? '',
            'type' => $resource->coupon->coupon_category ?? '',
        	'created_at' => (string)$resource->created_at ?? '',
            'destory_at' => $resource->destory_at ?? '',
            'is_used'=> (bool)$resource->is_used,
            'is_destory' => Carbon::now()->gt($resource->destory_at)
	        
        ];
        
        return $data;
    }
}
